<?
require("enroll_config.php");

$Query = "SELECT 
code,
aid,
date,
first_name,
last_name,
position,
company,
c_address,
city,
state,
zip,
country,
p_address,
pcity,
pstate,
pzip,	
pcountry,
email,
o_phone,
m_phone,
h_phone,
status FROM $table where aid='$aid' order by date desc";

$r=myQuery($Query);

$QueryEvening = "select code,presented from med_aevening where id='$aid'";
$rEvening = myQuery($QueryEvening);

header("Content-type:application/vnd.ms-excel");  
header("Content-Disposition:filename=". $rEvening[0][0]."_en_". date("Ymd").".xls");  

echo "Acuity Evening\t";
echo "Date\t";
echo "First name\t";
echo "Last name\t";
echo "Position\t";
echo "Company\t";
echo "Company address/street\t";
echo "Company city\t";
echo "Company state\t";
echo "Company zip\t";
echo "Company country\t";
echo "Private address/street\t";
echo "Private city\t";
echo "Private state\t";
echo "Private zip\t";
echo "Private country\t";
echo "Email\t";
echo "Office phone\t";
echo "Mobile phone\t";
echo "Home phone\t";
echo "Status\t\n";

for ($i=0;$i<count($r);$i++){

for ($j=0; $j < 22; $j++) {
$r[$i][$j] = str_replace("\n", " ", $r[$i][$j]);
$r[$i][$j] = str_replace("\r", " ", $r[$i][$j]);
if (empty($r[$i][$j])) {
	$r[$i][$j] = "(empty)";
}
}

/*$Query = "select presented from med_aevening where id='".$r[$i][1]."'";
$r1 = myQuery($Query);
echo $r1[0][0] . " \t"; */
echo $rEvening[0][1] . " \t";
echo $r[$i][2] . " \t"; 
echo $r[$i][3] . " \t"; 
echo $r[$i][4] . " \t"; 
echo $r[$i][5] . " \t"; 
echo $r[$i][6] . " \t"; 
echo $r[$i][7] . " \t"; 
echo $r[$i][8] . " \t"; 
echo $r[$i][9] . " \t"; 
echo $r[$i][10] . " \t"; 
echo $r[$i][11] . " \t"; 
echo $r[$i][12] . " \t"; 
echo $r[$i][13] . " \t"; 
echo $r[$i][14] . " \t"; 
echo $r[$i][15] . " \t"; 
echo $r[$i][16] . " \t"; 
echo $r[$i][17] . " \t"; 
echo $r[$i][18] . " \t"; 
echo $r[$i][19] . " \t"; 
echo $r[$i][20] . " \t"; 
echo $r[$i][21] . " \t\n"; 
}
?>